package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {


    @Select("select t_permission.id from t_role_permission,t_permission " +
            "where t_role_permission.role_id = #{id} and t_role_permission.permission_id = t_permission.id")
    List<Integer> findRolePermissionByRoleId(@Param("id") Integer id);


    @Delete("delete from t_role_permission where role_id = #{id}")
    Integer deleteRolePermissionByRoleId(@Param("id") Integer id);

    @Insert("insert into t_role_permission values(#{id},#{permissionId})")
    Integer addRolePermission(@Param("id")Integer id, @Param("permissionId")Integer permissionId);


    @Select("select t_menu.id from t_role_menu,t_menu where " +
            "t_role_menu.role_id = #{id} and t_role_menu.menu_id = t_menu.id")
    List<Integer> findRoleMenuByRoleId(@Param("id")Integer id);

    @Delete("delete from t_role_menu where role_id = #{id}")
    Integer deleteRoleMenuByRoleId(@Param("id")Integer id);

    @Insert("insert into t_role_menu values(#{id},#{menuId})")
    Integer addRoleMenu(@Param("id")Integer id,@Param("menuId") Integer menuId);
}
